<?php

class CmsComment extends AppModel
{
    var $name = 'CmsComment';
	var $validate = array(
		'body' => array('rule'=>'notEmpty'),
	);
	var $fieldProperties = array(
		'body' => array(
			'type' => 'textarea',
			'group' => 'add',
			'label'=>'Comment'
		),		
	);
	const PUBLISH = 1;
	const UNPUBLISH = 0;

	
	//var $additionalFields = array('name', 'url');
		
	function afterInitialize()
	{	
		parent::afterInitialize();	
		if(!$this->Behaviors->attached('Users.UserContent')) 
		{
			$this->Behaviors->attach('Users.UserContent',array('posterModels' => array('Users.User', 'Users.Guest')));			
		}
		//$this->actsAs['Users.UserContent']['posterModels'][] = 'Users.Guest';
	}
	function name($record)
	{
		if(!$record[$this->alias]['poster_entity'])
		{
			return false;
		}
		$posterEntity = $record[$this->alias]['poster_entity'];
		if(strpos($record[$this->alias]['poster_entity'], '.'))
		{
			$posterEntity = end(explode('.', $record[$this->alias]['poster_entity']));
		}
		if(!isset($record[$this->alias]['poster']))
			return __("No-one");
		return $record[$this->alias]['poster'][$posterEntity]['full_name'];
	}
	
	function url($record)
	{
		if(!$record[$this->alias]['poster_entity'])
		{
			return false;
		}
		$posterEntity = $record[$this->alias]['poster_entity'];
		if(strpos($record[$this->alias]['poster_entity'], '.'))
		{
			$posterEntity = end(explode('.', $record[$this->alias]['poster_entity']));
		}
		if(!isset($record[$this->alias]['poster'][$posterEntity]['profile_url']))
			return "/";
		return $record[$this->alias]['poster'][$posterEntity]['profile_url'];		
	}	
}

?>